home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python151_Src.lha / Python1.5_Source / Amiga / _dup2.c < prev    next >
C/C++ Source or Header  |  1998-12-25  |  1KB  |  72 lines

  1. RCS_ID_C="$Id: _dup2.c,v 4.1 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      _dup2.c - duplicate a file descriptor (SAS/C)
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <ios1.h>
  11. #include <fcntl.h>
  12. #include <stdlib.h>
  13. #include <dos.h>
  14. #define USE_BUILTIN_MATH
  15. #include <string.h>
  16. #include <errno.h>
  17. #include <dos/dos.h>
  18. #include <proto/dos.h>
  19.  
  20. #include <bsdsocket.h>
  21. #include "libcheck.h"
  22.  
  23. /****** net.lib/dup2 **********************************************************
  24.     SEE ALSO
  25.         dup()
  26. *******************************************************************************
  27. */
  28.  
  29.  
  30. int
  31. __dup2(int old_fd, int new_fd)
  32. {
  33.   struct UFB *ufb;
  34.   int ufbflg;
  35.  
  36.   /*
  37.    * Check if there is nothing to do
  38.    */
  39.   if (old_fd == new_fd)
  40.     return old_fd;
  41.  
  42.   /*
  43.    * Check for the break signals
  44.    */
  45.   __chkabort();
  46.  
  47.   __close(new_fd);
  48.  
  49.   /*
  50.    * Find the ufb * for the old FD
  51.    */
  52.   if ((ufb = __chkufb(old_fd)) == NULL) {
  53.     errno = EBADF;
  54.     return -1;
  55.   }
  56.  
  57.   ufbflg = ufb->ufbflg;
  58.  
  59.   /* 
  60.    * The brain dead UFB system won't allow duplicating ordinary files
  61.    */
  62.   if ((ufbflg & UFB_SOCK) == UFB_SOCK) {
  63.     /* needs bsdsocket.library -- I.J. */
  64.     if(!checksocketlib()) return -1;
  65.     return Dup2Socket(old_fd, new_fd);
  66.   } else {
  67.     errno = EBADF;
  68.     return -1;
  69.   }
  70.  
  71. }
  72.